#include "pch.h"
#include <iostream>
#include <map>
#include <vector>

using namespace std;

class Solution {
public:
	int maxArea(vector<int>& height) {
		int len = height.size();
		if (len < 2) return 0;

		int head = 0, tail = len - 1;
		int area = 0;
		int areaNew = 0;
		int width, high;
		while (head < tail)
		{
			width = tail - head;
			high = (height[head] > height[tail]) ? height[tail--] : height[head++];
			areaNew = width * high;
			if (areaNew>area)
			{
				area = areaNew;
			}
		}
		return area;
	}
};

int main()
{
	Solution s;
	vector<int> arr{ 1,8,6,2,5,4,8,3,7 };
	int res = s.maxArea(arr);
	cout << res << endl;

	return 0;
}